/*
 * @Author: your name
 * @Date: 2021-04-12 00:21:10
 * @LastEditTime: 2021-11-29 17:37:58
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /fun_android/lib/view_model/structure_model.dart
 */
import 'package:fun_android/model/article.dart';
import 'package:fun_android/provider/view_state_list_model.dart';
import 'package:fun_android/provider/view_state_refresh_list_model.dart';
import 'package:fun_android/service/wan_android_repository.dart';

import 'favourite_model.dart';

class StructureCategoryModel extends ViewStateListModel {
  @override
  Future<List> loadData({required int pageNum}) async {
    return await WanAndroidRepository.fetchTreeCategories();
  }
}

class StructureListModel extends ViewStateRefreshListModel {
  final int cid;

  StructureListModel(this.cid);

  @override
  Future<List> loadData({required int pageNum}) async {
    return await WanAndroidRepository.fetchArticles(pageNum, cid: cid);
  }

  @override
  onCompleted(List data) {
    GlobalFavouriteStateModel.refresh(data as List<Article>);
  }
}

/// 网址导航
class NavigationSiteModel extends ViewStateListModel {
  @override
  Future<List> loadData({required int pageNum}) async {
    return await WanAndroidRepository.fetchNavigationSite();
  }
}
